package com.guomao.controller;


import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Controller
public class ControllerD {
    @RequestMapping("/main")
    public String mainMethod() {
        System.out.println("mainMethod...");
        return "main";
    }


    @RequestMapping("/handle1")
    public String handle1() {
        System.out.println("handle1...");
        return "forward:/main";
    }

    @RequestMapping("/handle2")
    public void handle2(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("handle2...");
        request.getRequestDispatcher("/main").forward(request, response);
//        return "forward:/main";
    }


    @RequestMapping("/handle3")
    public String handle3() {
        System.out.println("handle3...");
        return "redirect:/main";
    }

    @RequestMapping("/handle4")
    public void handle4(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("handle4...");
//        response.sendRedirect("/mvc/main");
        response.sendRedirect(request.getContextPath() + "/main");
//        return "forward:/main";
    }

    /*@RequestMapping("/handle5")
    public String handle5() {
        return "info";
    }*/

}
